<!-- 此页面没做loaded处理（图片是否加载成功/失败），因为套层级太多，太复杂，如有需要，需要去cart页面（购物车页面）参考 -->
<template>
	<view class="container">
		<!-- 头部轮播 -->
		<view class="carousel-section">
			<swiper class="carousel" circular autoplay="true" duration="1000" @change="swiperChange">
				<swiper-item v-for="(item, index) in allBox.banner" :key="index" class="carousel-item" @click="navToDetailPage({title: '轮播广告'})">
					<image :src="item.img" />
				</swiper-item>
			</swiper>

			<!-- 自定义swiper指示器 -->
			<view class="swiper-dots">
				<text class="num">{{swiperCurrent+1}}</text>
				<text class="sign">/</text>
				<text class="num">{{swiperLength}}</text>
			</view>
		</view>
		<!-- 分类 -->
		<view class="content">
			<view class="company_name">
				<image src="../../static/missing-face.png"></image>
				<view class="company_name_right">
					<text class="company_name_right_name">{{allBox.enterprise_name}}</text>
					<view class="company_name_right_money">
						赠送余额
						<text>{{allBox.Balance}}</text>
					</view>
				</view>
				<view class="company_name_announcement">
					<text class="mallicon icon-laba" @click="toDetail(0,1)"></text>
				</view>
			</view>
			<view class="company_welfare" @click="toWelfare()">
				<view class="company_welfare_left">
					<image src="../../static/1tab-home-current.png"></image>
					<text>公司赠送福利记录</text>
				</view>
				<text class="mallicon icon-xiangyou"></text>
			</view>
			<view class="company_news">
				<view class="f-header m-t">
					<image src="/static/temp/h1.png"></image>
					<view class="tit-box">
						<text class="tit">公司推文</text>
					</view>
				</view>
				<view class="company_news_box">
					<view class="company_news_box_eve" @click="toDetail(item.id,2)"  v-for="(item, index) in allBox.article" :key="index" >
						<image src="../../static/1tab-cart-current.png"></image>
						<text>{{item.title}}</text>
					</view>
					<!-- <view class="company_news_box_eve" @click="toDetail()">
						<image src="../../static/1tab-cart-current.png"></image>
						<text>这里是推文2</text>
					</view>
					<view class="company_news_box_eve" @click="toDetail()">
						<image src="../../static/1tab-cart-current.png"></image>
						<text>这里是推文3</text>
					</view> -->
					<!-- <view class="company_news_box_btn" @click="toDetail()">
						<text>查看更多>></text>
					</view> -->
				</view>
			</view>
			<view class="company_introduce">
				<view class="f-header m-t">
					<image src="/static/temp/h1.png"></image>
					<view class="tit-box">
						<text class="tit">公司简介</text>
					</view>
					<!-- <text class="mallicon icon-you"></text> -->
				</view>
				<view class="company_introduce_news" v-html="allBox.introduction">
				</view>
			</view>
			<block>
				<!-- 分类推荐楼层 -->
				<view class="f-header m-t">
					<image src="/static/temp/h1.png"></image>
					<view class="tit-box">
						<text class="tit">推荐产品</text>
					</view>
					<!-- <text class="mallicon icon-you"></text> -->
				</view>
				<view class="class-floor">
					<view class="guess-section">
						<view v-for="(goods, index2) in allBox.goods" :key="index2" class="guess-item" @click="navToDetailPage(goods.id)">
							<view class="image-wrapper">
								<image :src="goods.logo" class="loaded" mode="aspectFill" lazy-load></image>
							</view>
							<text class="title clamp">{{goods.title}}</text>
							<text class="subtitle clamp">型号：{{goods.price_cost}}</text>
							<text class="price">￥{{goods.price_market}}</text>
						</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	// import bmap from "@/lib/bmap-wx.js"
	export default {

		data() {
			return {
				swiperCurrent: 0,
				swiperLength: 3,
				carouselList: [{
						imgUrl: "/static/banner-1.png",
						background: "rgb(245,95,113)",
					},
					{
						imgUrl: "/static/banner-2.png",
						background: "rgb(250,103,95)",
					},
					{
						imgUrl: "/static/banner-3.png",
						background: "rgb(250,123,49)",
					}
				],
				allBox:{}
			};
		},
		onShow() {
		},
		onLoad() {
			// ---------------------新接口---------------------
			this.getAllBox();
		},
		//下拉刷新
		onPullDownRefresh() {
			
		},
		methods: {
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
				// #ifndef MP
				// this.titleNViewBackground = this.carouselList[index].background;
				// #endif
			},
			// 去公司福利页
			toWelfare(){
				uni.navigateTo({
					url: '/pages/company/companyWelfare'
				})
			},
			// 企业公告
			toDetail(id,num){
				uni.navigateTo({
					url: '/pages/company/companyNewDetail?id='+id +'&num='+num
				})
			},
			//详情页
			navToDetailPage(item) {
				//为了模拟数据，正常项目里按照业务传值
				uni.navigateTo({
					url: `/pages/product/detail?goods=${this.$utils.putExtra(item)}`
				})
			},
			// ---------------------------------------------新---------------------------------------------
			getAllBox() {
				let that = this;
				that.$Request.get(that.$api.company.apiIndex).then(res => {
					that.allBox = res.data;
					console.log('企业信息',that.allBox)
				}, err => {
					console.log("err: " + JSON.stringify(err));
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
	}
	/* 头部 轮播图 */
	.carousel-section {
		position: relative;
	}

	.m-t {
		margin-top: 16upx;
	}
	.carousel {
		width: 100%;
		height: 294upx;

		// margin-top: 10rpx;
		.carousel-item {
			width: 100%;
			height: 100%;
			// padding: 0 28upx;
			overflow: hidden;
		}

		image {
			width: 100%;
			height: 100%;
			border-radius: 10upx;
		}
	}

	.swiper-dots {
		display: flex;
		position: absolute;
		left: 336upx;
		bottom: 50upx;
		width: 72upx;
		height: 36upx;
		background-image: url();
		background-size: 100% 100%;

		.num {
			width: 36upx;
			height: 36upx;
			border-radius: 50px;
			font-size: 24upx;
			color: #fff;
			text-align: center;
			line-height: 36upx;
		}

		.sign {
			position: absolute;
			top: 0;
			left: 50%;
			line-height: 36upx;
			font-size: 12upx;
			color: #fff;
			transform: translateX(-50%);
		}
	}

	.content {
		margin-top: -40rpx;
		background: #f2f2f2;
		position: relative;
		z-index: 6;
		overflow: hidden;
	}
	.company_name{
		padding: 2vw;
		background: #fff;
		margin-bottom: 2vw;
		display: flex;
		align-items: center;
		position: relative;
		image{
			width: 100rpx;
			height: 100rpx;
			margin-right: 2vw;
		}
		.company_name_right{
			.company_name_right_name{
				font-size: 32rpx;
			}
			.company_name_right_money{
				font-size: 28rpx;
				text{
					color: #B72B24;
					display: inline-block;
					margin-left: 2vw;
				}
			}
		}
		.company_name_announcement{
			position: absolute;
			top: 10rpx;
			right: 20rpx;
			// height: 30rpx;
			// width: 30rpx;
		}
	}
	.company_welfare{
		padding: 2vw;
		background: #fff;
		margin-bottom: 2vw;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.company_welfare_left{
			display: flex;
			align-items: center;
			image{
				width: 40rpx;
				height: 40rpx;
				margin-right: 2vw;
			}
			text{
				font-size: 30rpx;
			}
		}
	}
	.company_news{
		padding: 2vw;
		background: #fff;
		margin-bottom: 2vw;
		.company_news_box{
			padding: 0 2vw;
			.company_news_box_eve{
				display: flex;
				align-items: center;
				padding:2vw 0;
				border-bottom: 1rpx solid #eaeef1;
				image{
					width: 30rpx;
					height: 30rpx;
					margin-right: 2vw;
				}
				text{
					font-size: 30rpx;
					display: block;
					width: 80vw;
					overflow: hidden;
					text-overflow: ellipsis; 
					-o-text-overflow: ellipsis;
					white-space:nowrap;
				}
			}
			.company_news_box_btn{
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				color: #666;
				padding: 2vw 0;
			}
		}
	}
	.company_introduce{
		padding: 2vw;
		background: #fff;
		margin-bottom: 2vw;
		.company_introduce_news{
			font-size: 30rpx;
		}
	}
	
	.f-header {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100upx;
		padding: 6upx 30upx 8upx;
		// background: #fff;

		image {
			flex-shrink: 0;
			width: 50upx;
			height: 50upx;
			margin-right: 20upx;
		}

		.tit-box {
			// flex: 1;
			display: flex;
			flex-direction: column;
		}

		.tit {
			font-size: $font-lg +2upx;
			color: #font-color-dark;
			line-height: 1.3;
		}

		.tit2 {
			font-size: $font-sm;
			color: $font-color-light;
		}

		.icon-you {
			font-size: $font-lg +2upx;
			color: $font-color-light;
		}
	}

	/* 分类推荐楼层 */
	.class-floor {
		width: 100%;
		overflow: hidden;
		margin-bottom: 20upx;
		margin-top: -50upx;

		.title {
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			margin-top: 10rpx;
		}

		.subtitle {
			font-size: $font-sm;
			color: $font-color-light;
			line-height: 2.4;
		}

		.price {
			color: $uni-color-primary;
			font-size: $font-lg;
		}

		/* 猜你喜欢 */
		.guess-section {
			display: flex;
			flex-wrap: wrap;
			width: 750upx;
			background: #f2f2f2;
			margin-top: 40rpx;

			.guess-item {
				display: flex;
				flex-direction: column;
				background: #fff;
				width: 46vw;
				margin: 2vw;
				padding: 3vw;
				border-radius: 20rpx;
			}

			.image-wrapper {
				// width: 230upx;
				height: 260upx;
				flex-shrink: 0;
				position: relative;

				image {
					border-radius: 8upx;
				}
			}

			// image {
			// 	width: 230upx;
			// 	height: 260upx;
			// 	opacity: 1;
			// 	
			// }
		}
	}
</style>
